****APPENDIX TABLE C10-C12****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

cap drop others_sample state_sample corrupt_sample help_poor_sample income_sample living_sample life_sample

qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen others_sample=1 if e(sample)==1

qui reghdfe trust_religious_organizations wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen religion_sample=1 if e(sample)==1

qui reghdfe trust_state wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen state_sample=1 if e(sample)==1

qui reghdfe govt_corrupt wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen corrupt_sample=1 if e(sample)==1

qui reghdfe feelings_income wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen income_sample=1 if e(sample)==1

qui reghdfe standard_living wgrowth_rate_1 yob_ln_gdppc if sample==1 & trust_govt!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen living_sample=1 if e(sample)==1

//--------------------------------------------------------
//Create Table C10
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if others_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if others_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Trust in Others) keep(zwgrowth_rate_1) 
														  
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if religion_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if religion_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Trust Religious Organizations) keep(zwgrowth_rate_1) 														  
													   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if state_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if state_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Trust State Institutions) keep(zwgrowth_rate_1) 

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if corrupt_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if corrupt_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Government Corrupt) keep(zwgrowth_rate_1) 
													   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if income_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if income_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Feelings on Income) keep(zwgrowth_rate_1) 											   

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if living_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if living_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Standard of Living) keep(zwgrowth_rate_1) 
														 
//--------------------------------------------------------
//Create Table C11
//--------------------------------------------------------

qui reghdfe donate_money wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
gen donate_money_sample=1 if e(sample)==1
standardize donate_money
reghdfe zdonate_money zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
outreg2 using table_c11.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Gallup) keep(zwgrowth_rate_1) 

qui reghdfe volunteered_time wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
gen volunteered_time_sample=1 if e(sample)==1
standardize volunteered_time
reghdfe zvolunteered_time zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
outreg2 using table_c11.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Gallup) keep(zwgrowth_rate_1)
														  
qui reghdfe help_stranger wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
gen help_stranger_sample=1 if e(sample)==1
standardize help_stranger
reghdfe zhelp_stranger zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
outreg2 using table_c11.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Gallup) keep(zwgrowth_rate_1)
														  
qui reghdfe relatives_help wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
gen relatives_help_sample=1 if e(sample)==1
standardize relatives_help
reghdfe zrelatives_help zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode subregion_yob survey_year age $basic) cluster(ccode)
outreg2 using table_c11.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Gallup) keep(zwgrowth_rate_1)	

//--------------------------------------------------------
//Create Table C12
//--------------------------------------------------------

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if donate_money_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c12.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
														  Sample, Donate Money) keep(zwgrowth_rate_1) 
														  
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if volunteered_time_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c12.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Volunteered Time) keep(zwgrowth_rate_1) 														  
													   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if help_stranger_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c12.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Help Stranger) keep(zwgrowth_rate_1) 

qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if relatives_help_sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c12.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													     Survey Year FE x Survey FE, Yes, ///
													     Subcontinent FE x Cohort FE, Yes, ///
														 Sample, Help From Relatives) keep(zwgrowth_rate_1)	

//--------------------------------------------------------
//Create Table C13
//--------------------------------------------------------														 
														 
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_others
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c13.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													   Survey Year FE x Survey FE, Yes, ///
													   Subcontinent FE x Cohort FE, Yes, ///
													   Survey, Core + ESS + Afrobarometer) keep(zwgrowth_rate_1) 												   
													   
qui reghdfe trust_state wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_state
reghdfe ztrust_state zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c13.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													   Survey Year FE x Survey FE, Yes, ///
													   Subcontinent FE x Cohort FE, Yes, ///
													   Survey, Core + ESS + Afrobarometer) keep(zwgrowth_rate_1)													 
